package com.ncomz.cspace.members.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ncomz.cspace.members.dao.MembersDAO;
import com.ncomz.cspace.members.model.MembersVO;

/**
 * 
 * 1. ClassName		: MembersModifyController
 * 2. FileName		: MembersModifyController.java
 * 3. Package		: com.ncomz.cspace.members.controller
 * 4. Comment		: 회원정보를 수정함
 * 5. 작성자		: 이석균
 * 6. 작성일		: 2013. 8. 22. 오후 12:34:40
 */
@Controller
public class MembersModifyController {
	
	@Autowired
	MembersDAO mbDAO;

	/**
	 * 
	 * 1. MethodName	: members
	 * 2. ClassName		: MembersModifyController
	 * 3. 작성자		: 이석균
	 * 4. 작성일		: 2013. 8. 22. 오후 12:36:56
	 * 5. Comment		: 로그인되어있는 회원 정보를 가져옴
	 * @param param
	 * @return ModelAndView
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/membersmodify.do" )		
	public ModelAndView members(HttpSession session){
		
		
		ModelAndView mav = new ModelAndView();
		
		String member_id = (String)session.getAttribute("id");
		
		if ( member_id == null) {		//session check
			
			mav.setViewName("");
			return mav;
		}
		
		mav.addObject("id",member_id);
		
		mav.addObject("member_info", mbDAO.getMemberInfo(member_id));
		
		mav.setViewName("/members/members_modify");
		
		return mav;
	}
	
	/**
	 * 
	 * 1. MethodName	: modify
	 * 2. ClassName		: MembersModifyController
	 * 3. 작성자		: 이석균
	 * 4. 작성일		: 2013. 8. 22. 오후 12:37:50
	 * 5. Comment		: 변경된 회원정보를 수정함
	 * @param param
	 * @return String
	 * @param VO
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/member_modify.do")		//개인정보수정
	@ResponseBody
	public String modify(MembersVO VO, HttpSession session){
		String member_id = (String)session.getAttribute("id");

		VO.setMember_id(member_id);

		
		mbDAO.updateMember(VO);
		
		String end = "수정이 완료되었습니다.";
		return end;
	}
	
	
	
	
}